
var data=require("../src/js/a");
var axios=require("axios");


module.exports={
  //根据songUrl获取对应的歌曲信息
    getSongLists:(songUrl)=>{
        return axios.get(songUrl).then(function(values){
          values.data.data.song.list.forEach(value=>{
           // value.photoUrl=values.data.data.zhida.zhida_album.albumPic||values.data.data.zhida.zhida_singer.singerPic
            if(Reflect.ownKeys(values.data.data.zhida)[1].includes("zhida_album")){
              value.photoUrl=values.data.data.zhida.zhida_album.albumPic
            }
            else{
              value.photoUrl=values.data.data.zhida.zhida_singer.singerPic
            }
          })
            return  values.data.data.song.list
          }).catch(function(err){
            console.log(err)
          })
    },
    getSongSign:function(songUrl){
      var importantMessage=[] //存储songmid和songsign
     return this.getSongLists(songUrl).then(function(songList){
        //console.log(songList)
          songList.forEach(function(value){
            // console.log(value)
              var songmid=value.songmid;
              // console.log("songmid------"+songmid)
                    var datas = {
                        req: {
                          module: "CDN.SrfCdnDispatchServer",
                          method: "GetCdnDispatch",
                          param: { guid: "5596796864", calltype: 0, userip: "" },
                        },
                        req_0: {
                          module: "vkey.GetVkeyServer",
                          method: "CgiGetVkey",
                          param: {
                            guid: "5596796864",
                            songmid: [songmid],
                            songtype: [0],
                            uin: "2211207925",
                            loginflag: 1,
                            platform: "20",
                          },
                        },
                        comm: { uin: 2211207925, format: "json", ct: 24, cv: 0 },
                  };
                  let str = "abcdefghijklmnopqrstuvwxyz0123456789";
                  let count = Math.floor(Math.random() * 7 + 10);
                  let sign = "zza";
                  for (let i = 0; i < count; i++) {
                    sign += str[Math.floor(Math.random() * 36)];
                  }
                  sign += window.__sign_hash_20200305(
                    "CJBPACrRuNy7" + JSON.stringify(datas)
                  );
                  // console.log(sign)
                  importantMessage.push({songmid:songmid,sign:sign,songMessage:value})
          })
        //  console.log(importantMessage);
          return importantMessage;
      }).catch(err=>{
        console.log("出错了，"+err)
      })

    },
    getSongMedial:function(songUrl){
     var urlDes=[]
      this.getSongSign(songUrl).then(value=>{
        // console.log(value)
        // console.log(value);
       
       value.forEach(data=>{ 
        // var url='/act/cgi-bin/musics.fcg?sign=zzamyr92sclgp2f24a8772cdd22b3ec8eba2c153d4b7b9&loginUin=2211207925&hostUin=0&format=json&inCharset=utf8&outCharset=utf-8&notice=0&platform=yqq.json&needNewCode=0&data={"req":{"module":"CDN.SrfCdnDispatchServer","method":"GetCdnDispatch","param":{"guid":"5596796864","calltype":0,"userip":""}},"req_0":{"module":"vkey.GetVkeyServer","method":"CgiGetVkey","param":{"guid":"5596796864","songmid":["002a05Sr3wcGcs"],"songtype":[0],"uin":"2211207925","loginflag":1,"platform":"20"}},"comm":{"uin":2211207925,"format":"json","ct":24,"cv":0}}'
        //var url2='/act/cgi-bin/musics.fcg?sign=zza6562gq798i8df46892f626df589d0703ec79e0b855&loginUin=2211207925&hostUin=0&format=json&inCharset=utf8&outCharset=utf-8&notice=0&platform=yqq.json&needNewCode=0&data={"req":{"module":"CDN.SrfCdnDispatchServer","method":"GetCdnDispatch","param":{"guid":"5596796864","calltype":0,"userip":""}},"req_0":{"module":"vkey.GetVkeyServer","method":"CgiGetVkey","param":{"guid":"5596796864","songmid":["003MKOsN117gOs"],"songtype":[0],"uin":"2211207925","loginflag":1,"platform":"20"}},"comm":{"uin":2211207925,"format":"json","ct":24,"cv":0}}'
  var url1='/act/cgi-bin/musics.fcg?sign='+data.sign+'&loginUin=2211207925&hostUin=0&format=json&inCharset=utf8&outCharset=utf-8&notice=0&platform=yqq.json&needNewCode=0&data={"req":{"module":"CDN.SrfCdnDispatchServer","method":"GetCdnDispatch","param":{"guid":"5596796864","calltype":0,"userip":""}},"req_0":{"module":"vkey.GetVkeyServer","method":"CgiGetVkey","param":{"guid":"5596796864","songmid":["'+data.songmid+'"],"songtype":[0],"uin":"2211207925","loginflag":1,"platform":"20"}},"comm":{"uin":2211207925,"format":"json","ct":24,"cv":0}}'
        axios.get(url1).then(function(value){
          // let desUrl=value.data.req_0.data.midurlinfo[0].filename+"?guid=5596796864&vkey="+value.data.req_0.data.midurlinfo[0].vkey+"&uin=0&fromtag=66"
         // console.log(value.data.req_0.data.midurlinfo[0].purl);
          urlDes.push({obj:data,desUrl:value.data.req_0.data.midurlinfo[0].purl});
        })
       })
     })
     return urlDes;
    }
}
                   